//bange_layer.cpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <bange_layer.hpp>
#include <bange_layercolor.hpp>

void bange::layer::RegisterVM(lua_State *vm){
	
}

bange::layer::layer(cpSpace *space, lua_State *vm):bange::behavior(vm){
	this->scenespace = space;
	this->visible = true;
	this->processlayer = true;
	this->type = bange::layer::None;
}

bool bange::layer::NewIndex(lua_State *vm){
	//userdata, key, data
	if (this->bange::behavior::NewIndex(vm)){
		return true;}
	if (strcmp("visible", lua_tostring(vm, 2)) == 0 && lua_isboolean(vm, 3)){
		this->visible = static_cast<bool>(lua_toboolean(vm, 3));
		return true;}
	if (strcmp("processlayer", lua_tostring(vm, 2)) == 0 && lua_isboolean(vm, 3)){
		this->processlayer = static_cast<bool>(lua_toboolean(vm, 3));
		return true;}
	return false;
}

bool bange::layer::Index(lua_State *vm){
	//userdata, key
	if (this->bange::behavior::Index(vm)){
		return true;}
	if (strcmp("visible", lua_tostring(vm, 2)) == 0){
		lua_pushboolean(vm, static_cast<int>(this->visible));
		return true;
	}
	if (strcmp("processlayer", lua_tostring(vm, 2)) == 0){
		lua_pushboolean(vm, static_cast<int>(this->processlayer));
		return true;
	}
	if (strcmp("type", lua_tostring(vm, 2)) == 0){
		lua_pushnumber(vm, static_cast<lua_Number>(this->type));
		return true;
	}
	return false;
}

void bange::layer::SetVisible(bool visible){
	this->visible = visible;
}

bool bange::layer::GetVisible(void){
	return this->visible;
}

void bange::layer::CleanVM(lua_State *vm){
	this->bange::behavior::CleanVM(vm);
}

bange::layer::~layer(){
	cout << "bange::layer destructor for: " << this << endl;
}
